<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%--退单审核弹框--%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>申诉审核</title>
    <%@ include file="../../header.jsp" %>
    <link rel="stylesheet" type="text/css"
          href="${basePath}/static/css/production.css?v=${version}"/>
    <style>
        body, a {
            font-size: 14px;
            color: #555;;
        }

        .wordCount {
            position: relative;
        }

        .wordCount textarea {
            width: 100%;
            height: 100px;
        }

        .wordCount .wordwrap {
            position: absolute;
            right: 6px;
            bottom: 6px;
        }

        .wordCount .word {
            color: red;
            padding: 0 4px;;
        }
    </style>
</head>
<body>
<div style="border:1px solid #e6e6e6;padding-bottom: 50px;padding:10px 20px">
    <div class="panel-data">
        <div id="Details">
            <table style="width:100%;border-collapse:separate;border-spacing:10px;" class="crm-table">
                <tr>
                    <td>申诉人：</td>
                    <td>${order.flowUserName}</td>
                </tr>
                <tr>
                    <td>申述时间：</td>
                    <td><fmt:formatDate value="${order.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                </tr>
                <tr >
                    <td>申述原因：</td>
                    <td><p class="line2" title="${order.appealReason}">申诉原因:${order.appealReason}</p></td>
                </tr>
                <tr>
                    <td colspan="2">
                        <span class="form-label">申诉附件：</span>
                        <input type="hidden" value="flsc_order_${order.timeoutPunishId}_${order.id}_deduction" id="updateFileId">
                        <ul class="data-warp  f-cb" id="deductionAppealAnnex">
                        </ul>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<div class="panel-data">
    <div id="Details1">
        <table style="width:100%;border-collapse:separate;border-spacing:10px;" class="crm-table">
            <tr>
                <td>审核人：</td>
                <td>${order.reviewerName}</td>
            </tr>
            <tr>
                <td>审核时间：</td>
                <td><fmt:formatDate value="${order.reviewTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
            </tr>
            <c:if test="null != order.oldPoint">
            <tr>
                <td>扣罚数量:</td>
                <td>${order.oldPoint}</td>
                <td>扣罚单位:</td>
                <td>分</td>
            </tr>
            </c:if>
            <c:if test="null != order.newMoney">
                <tr>
                    <td>扣罚数量:</td>
                    <td>${order.newMoney}</td>
                    <td>扣罚单位:</td>
                    <td>元</td>
                </tr>
            </c:if>
            <tr>
                <td>审核备注:</td>
                <td>${order.overruleReason}</td>
            </tr>
        </table>
    </div>
</div>
<jsp:include page="/WEB-INF/jsp/footer.jsp"/>
<script type="text/javascript"
        src="${basePath}/static/js/choose.extend.js?v=${version}"></script>
<script type="text/javascript" src="${basePath}/static/js/zzsc/production/sc_common.js?v=${version}"></script>
<script type="text/javascript"
        src="${basePath}/static/js/verificationTool.js?v=${version}"></script>

<script type="text/javascript">

    //获取输入框的内容和长度
    var wordCount = $("#wordCount"),
        textArea = wordCount.find("textarea"),
        word = wordCount.find(".word");
    //用于计算输入内容之后，显示输入字多少
    statInputNum(textArea, word);

    $(function () {

        //回显申诉人上传附件
        findSingleBackFiles($("#updateFileId").val(), "deductionAppealAnnex", 4, "appeal");//申诉人上传
        //回显审核人上传的附件
        findSingleBackFiles($("#updateFileId").val(), "updateFiles", 1, "szsh");

        //退单申请附件命名规则  flsc_order_订单id_deduction_上传人类型
        //绑定上传
        var uploadType = "szsh";
        var fileId = $("#updateFileId").val();
        var exts = "doc|docx|xls|xlsx|jpg|jpeg|png|rar|zip";
        bindUpload($("#flscDeductionUpload"), 20 * 1024, exts, fileId, sysInfo.cmsBaseUrl, true, true, uploadType, 5);
    });


    /**
     * 退单审核
     * @param type  1审核通过，2审核不通过
     */
    function deductionAppealReviewPass(type) {
        //记录传递的值
        var remark = $("#remark").val();//审核说明
        var deductionNumber = $("#deductionNumber").val();//扣罚分数
        var deductionMoney = $("#deductionMoney").val();//扣罚金额

        //审核通过
        // debugger;
        if (type == 1) {
            var moneyReg = /^[0-9]{1,6}(\.[0-9]{2}|\.[0-9]|)$/;
            if (isEmpty(deductionMoney) || !moneyReg.test(deductionMoney)) {
                DGG.Layer.message('申诉通过时，扣罚金额只能为1-6位数字，最多小数点后两位数字', {icon: '0'});
                return false;
            }

            var numberReg = /^[0-9]{1,3}(\.[0-9]|)$/;
            if (isEmpty(deductionNumber) || !numberReg.test(deductionNumber)) {
                DGG.Layer.message('申诉通过时，扣罚分数只能为1-3位数字，最多小数点后一位数字', {icon: '0'});
                return false;
            }

            if (!isEmpty(remark) && checkSymbol(remark)) {
                DGG.Layer.message('审核说明不能有特殊字符', {icon: '0'});
                return false;
            }
        }

        if (type == 2) {
            if (isEmpty(remark) || checkSymbol(remark)) {
                DGG.Layer.message('申诉驳回时，审核说明不能为空或者有特殊字符', {icon: '0'});
                return false;
            }
        }

        var sucess = type == 1 ? '审核通过' : '审核不通过';
        DGG.Layer.confirm("确定" + sucess + "吗？", {'title': '操作'}, function () {
            DGG.Layer.loading.start();
            $.ajax({
                url: sysInfo.basePath + "/flsc/nodeOverdue/deductionAppealReview.do",
                type: "post",
                dataType: "json",
                data: {
                    "remark": remark,
                    "deductionNumber": deductionNumber,
                    "deductionMoney": deductionMoney,
                    "id": $("#orderTimeoutPunishId").val(),
                    "appealId": $("#orderId").val(),
                    "type": type
                },
                success: function (data) {
                    DGG.Layer.loading.done();
                    if (data.code == 1) {
                        DGG.Layer.message(data.msg, {icon: '0'});
                    } else {
                        var page_index = window.parent.page_index;
                        if (typeof(page_index) != "undefined" && page_index == "detail") {
                            window.parent.location.reload();
                        } else {
                            window.parent.dataTableReload();
                            window.parent.layer.closeAll();
                        }
                        window.parent.DGG.Layer.message(data.data, {icon: '1'});
                    }
                }
            })
        })
    };


    //用于计算输入框输入内容之后，显示输入多少个字
    function statInputNum(textArea, numItem) {
        var max = numItem.text(),
            curLength;
        textArea[0].setAttribute("maxlength", max);
        curLength = textArea.val().length;
        numItem.text(max - curLength);
        textArea.on('input propertychange', function () {
            numItem.text(max - $(this).val().length);
        });
    }


    /**
     * 根据选择的标签，切换显示退单的内容
     * @param obj 需要显示的标签
     */
    function selectLabel(obj) {
        if (obj == 1) {
            $("#Details").show();
            $("#record").hide();
        } else {
            $("#Details").hide();
            $("#record").show();
        }
    }
    function bindUpload(obj, size, exts, fileId, uploadBaseUrl, showIcon, isRemove, uploadUserType, uploadNum) {
        if ("" == fileId || null == fileId) {
            alert("上传控件未设置文件ID");
        }
        layui.use('upload', function () {
            var upload = layui.upload;
            upload.render({
                elem: obj
                , size: size//最大允许
                , accept: "file"
                , exts: exts
                , url: uploadBaseUrl + '/api/cms/file/upload.do'
                , multiple: false
                , auto: false//取消自动上传
                , data: {fileId: fileId}
                , choose: function (obj) {
                    obj.preview(function (index, file) {
                        //如果当前类型上传附件数量大于页面附件数量，取消上传
                        if (!isEmpty(uploadUserType) && !isEmpty(uploadNum)) {
                            if ($("." + uploadUserType).length >= uploadNum) {
                                DGG.Layer.message("附件最多上传" + uploadNum + "个", {icon: '2'});
                                return false;
                            }
                        }
                        obj.upload(index, file)
                    });
                }
                , before: function (obj) {
                    DGG.Layer.loading.start();
                }
                , done: function (res) {
                    DGG.Layer.loading.done();
                    if (res.code == 0) {
                        var file = res.data;
                        var filePath = file.filepath;
                        var fileRealPath = file.filepath;
                        var fileid = file.fileid;
                        if (!isImgFile(filePath)) {
                            filePath = sysInfo.baseStaticUrl + "/static/images/pereview_default.png";//一张固定的文件图片
                        }
                        var fileHtml = '<li title=' + file.filename + '>';
                        if (showIcon) {
                            fileHtml += '<div class="data-img">';
                            //判断是否可以删除
                            if (isRemove) {
                                fileHtml += '<a href="javascript:void(0)" class="remove-upload" title="删除" onclick="cancelFile(\'' + uploadBaseUrl + '\',\'' + fileid + '\',\'' + file.filename + '\', this)"></a>';
                            }
                            fileHtml += '<div class="center ' + uploadUserType + '"  data-path=' + fileRealPath + ' data-filename = ' + file.filename + '>';
                            fileHtml += '<img data-fileId="' + fileid + '" src="' + filePath + '" alt="' + file.filename + '" class="layui-upload-img">';
                            fileHtml += '</div>';
                            fileHtml += '</div>';
                        }
                        fileHtml += '<p>' + file.filedate + '</p>';
                        fileHtml += '<a href="javascript:void(0)"  onclick="downloadFile(\'' + uploadBaseUrl + '\',\'' + fileRealPath + '\',\'' + file.filename + '\')">' + file.filename + '</a>';
                        fileHtml += '</li>';
                        $(obj).parent().before(fileHtml);
                    } else {
                        DGG.Layer.message(res.msg, {icon: '2'});
                    }
                }, error: function () {
                    DGG.Layer.loading.done();
                }
            });
        });

    }
    /**
     * 获取生产相关附件公共函数方法
     * fileId 附件ID
     * divId 附件显示div区域
     * type 类型，1生产附件，2生产作废附件，3商机附件，4订单附件
     * uploadType 上传附件类型
     * */
    function findSingleBackFiles(fileId, divId, type,uploadUserType) {
        //$('#' + divId).html("");
        var findFilesUrl = sysInfo.cmsBaseUrl + "/api/cms/file/find_files.do";
        DGG.Layer.loading.start();
        $.ajax({
            type: "post",
            url: findFilesUrl,
            dataType: 'json',
            data: {fileId: fileId+"_"+uploadUserType},
            success: function (result) {
                if (result.code == 0) {
                    var files = result.data;
                    if (null != files && files.length > 0) {
                        for (var i = 0; i < files.length; i++) {
                            var file = files[i];
                            var filePath = file.filepath;
                            var fileRealPath = file.filepath;
                            var fileid = file.fileid;
                            if (!isImgFile(filePath)) {
                                filePath = sysInfo.baseStaticUrl + "/static/images/pereview_default.png";//一张固定的文件图片
                            }
                            var fileHtml = '<li title=' + file.filename + '>';
                            fileHtml += '<div class="data-img">';
                            if (1 == type) {
                                fileHtml += '<a href="javascript:void(0)" class="remove-upload" title="作废附件" onclick="cancelFile(\'' + fileid + '\',\'' + file.filename + '\', this)"></a>';
                            } else if (2 == type) {
                                fileHtml += '<a href="javascript:void(0)" class="enable-upload" title="恢复附件" onclick="recoverFile(\'' + fileid + '\',\'' + file.filename + '\', this)"></a>';
                            }
                            fileHtml += '<div class="center ' + uploadUserType + '"   data-path=' + fileRealPath + ' data-filename = ' + file.filename + '>';
                            fileHtml += '<img data-fileId="' + fileid + '" src="' + filePath + '" alt="' + file.filename + '" class="layui-upload-img dgg-file-imgpop">';
                            fileHtml += '</div>';
                            fileHtml += '</div>';
                            fileHtml += '<p>' + file.filedate + '</p>';
                            fileHtml += '<a href="javascript:void(0)" onclick="downloadFile(\'' + sysInfo.cmsBaseUrl + '\',\'' + fileRealPath + '\',\'' + file.filename + '\')">' + file.filename + '</a>';
                            fileHtml += '</li>';
                            $('#' + divId).prepend(fileHtml);
                        }
                    } else {
                        //$('#' + divId).prepend(" <li>无附件</li>");
                    }
                } else {
                    DGG.Layer.message(result.msg, {icon: '2'});
                }
                DGG.Layer.loading.done();
            },
            error: function (error) {
                DGG.Layer.loading.done();
                DGG.Layer.message("服务器异常，请联系管理员", {icon: '2'});
            }
        });
    }
    /**
     * 判断是否是图片
     * @param filepath
     * @returns {boolean}
     */
    function isImgFile(filepath) {
        var extStart = filepath.lastIndexOf(".");
        var ext = filepath.substring(extStart, filepath.length).toUpperCase();
        return (ext == ".BMP" || ext == ".PNG" || ext == ".GIF" || ext == ".JPG" || ext == ".JPEG");
    }
    function downloadFile(uploadBaseUrl, fileUrl, fileName) {
        DGG.Layer.message("下载文件【" + fileName + "】", {icon: '1'});
        fileName = encodeURI(encodeURI(fileName));
        var uploadUrl = uploadBaseUrl + "/api/cms/file/download.do";
        uploadUrl += "?fileUrl=" + fileUrl + "&fileName=" + fileName;
        $('body').append('<a href="" id="download_goto" target="_blank"></a>');
        $('#download_goto').attr('href', uploadUrl);
        $('#download_goto').get(0).click();
    }
    /**
     * 作废文件,因生产订单jsp其他页面使用不到，复制到公用这里
     * @param fileId
     * @param fileName
     */
    function cancelFile(fileId,fileName,obj){
        DGG.Layer.confirm('确认提示',{'title':'确认作废附件?'},function() {
            DGG.Layer.loading.start();
            $.ajax({
                type: 'post',
                data: {'fileId': fileId, 'fileName': fileName},
                dataType: 'json',
                url: sysInfo.cmsBaseUrl + '/api/cms/file/delete_file_by_logic.do',
                success: function (result) {
                    DGG.Layer.loading.done();
                    if (result.code === 0) {
                        $(obj).parents('li').remove();
                        DGG.Layer.message(result.msg,{icon:'1'});
                    } else {
                        DGG.Layer.message(result.msg,{icon:'2'});
                    }
                },
                error: function () {
                    DGG.Layer.loading.done();
                    DGG.Layer.message("服务器异常，请联系管理员！",{icon:'2'});
                }
            });
        });
    }
    /**
     * 作废文件,因生产订单jsp其他页面使用不到，复制到公用这里
     * @param fileId
     * @param fileName
     */
    function cancelFile(fileId,fileName,obj){
        DGG.Layer.confirm('确认提示',{'title':'确认作废附件?'},function() {
            DGG.Layer.loading.start();
            $.ajax({
                type: 'post',
                data: {'fileId': fileId, 'fileName': fileName},
                dataType: 'json',
                url: sysInfo.cmsBaseUrl + '/api/cms/file/delete_file_by_logic.do',
                success: function (result) {
                    DGG.Layer.loading.done();
                    if (result.code === 0) {
                        $(obj).parents('li').remove();
                        DGG.Layer.message(result.msg,{icon:'1'});
                    } else {
                        DGG.Layer.message(result.msg,{icon:'2'});
                    }
                },
                error: function () {
                    DGG.Layer.loading.done();
                    DGG.Layer.message("服务器异常，请联系管理员！",{icon:'2'});
                }
            });
        });
    }

</script>
</body>
</html>
